<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>订单售后管理</title>
    <meta name="decorator" content="default"/>
    <script type="text/javascript">
        $(document).ready(function () {

        });

        function page(n, s) {
            $("#pageNo").val(n);
            $("#pageSize").val(s);
            $("#searchForm").submit();
            return false;
        }
    </script>
</head>
<body>
<ul class="nav nav-tabs">
    <li class="active"><a href="${ctx}/shop/order/hkShopUserOrderAfter/">订单售后列表</a></li>
    <%--<shiro:hasPermission name="shop:order:hkShopUserOrderAfter:edit"><li><a href="${ctx}/shop/order/hkShopUserOrderAfter/form">订单售后添加</a></li></shiro:hasPermission>--%>
</ul>
<form:form id="searchForm" modelAttribute="hkShopUserOrderAfter" action="${ctx}/shop/order/hkShopUserOrderAfter/"
           method="post" class="breadcrumb form-search">
    <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
    <input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
    <ul class="ul-form">
        <li><label>订单号：</label>
            <form:input path="ordernumber" htmlEscape="false" maxlength="20" class="input-medium"/>
        </li>
        <li><label>售后状态：</label>
            <form:select path="afterstate" class="input-medium">
                <form:option value="" label=""/>
                <form:options items="${fns:getDictList('hk_shop_order_afterState')}" itemLabel="label" itemValue="value"
                              htmlEscape="false"/>
            </form:select>
        </li>
        <li><label>售后类型：</label>
            <form:select path="type" class="input-medium">
                <form:option value="" label=""/>
                <form:options items="${fns:getDictList('hk_shop_order_after_type')}" itemLabel="label" itemValue="value"
                              htmlEscape="false"/>
            </form:select>
        </li>
        <li><label>退款联系人：</label>
            <form:input path="refundcontact" htmlEscape="false" maxlength="100" class="input-medium"/>
        </li>
        <li><label>收货人：</label>
            <form:input path="consignee" htmlEscape="false" maxlength="50" class="input-medium"/>
        </li>
        <li><label>手机号：</label>
            <form:input path="phone" htmlEscape="false" maxlength="20" class="input-medium"/>
        </li>
        <li><label>快递单号：</label>
            <form:input path="couriernumber" htmlEscape="false" maxlength="50" class="input-medium"/>
        </li>
        <li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/></li>
        <li class="clearfix"></li>
    </ul>
</form:form>
<sys:message content="${message}"/>
<table id="contentTable" class="table table-striped table-bordered table-condensed">
    <thead>
    <tr>
        <th>订单号</th>
        <th>售后状态</th>
        <th>用户</th>
        <th>售后类型</th>
        <th>退款联系人</th>
        <th>退款原因</th>
        <th>退款电话</th>
        <th>投诉原因</th>
        <th>收货人</th>
        <th>手机号</th>
        <th>快递单号</th>
        <th>快递公司</th>
        <th>更新时间</th>
        <th>备注</th>
        <shiro:hasPermission name="shop:order:hkShopUserOrderAfter:edit">
            <th>操作</th>
        </shiro:hasPermission>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${page.list}" var="hkShopUserOrderAfter">
        <tr>
                <%--<td><a href="${ctx}/shop/order/hkShopUserOrderAfter/form?id=${hkShopUserOrderAfter.id}">
                        ${hkShopUserOrderAfter.ordernumber}
                </a></td>--%>
            <td>
                    ${hkShopUserOrderAfter.ordernumber}
            </td>
            <td>
                    ${fns:getDictLabel(hkShopUserOrderAfter.afterstate, 'hk_shop_order_afterState', '')}
            </td>
            <td>
                    ${hkShopUserOrderAfter.user.name}
            </td>
            <td>
                    ${fns:getDictLabel(hkShopUserOrderAfter.type, 'hk_shop_order_after_type', '')}
            </td>
            <td>
                    ${hkShopUserOrderAfter.refundcontact}
            </td>
            <td>
                    ${hkShopUserOrderAfter.refundreason}
            </td>
            <td>
                    ${hkShopUserOrderAfter.refundtelephone}
            </td>
            <td>
                    ${hkShopUserOrderAfter.complaintreason}
            </td>
            <td>
                    ${hkShopUserOrderAfter.consignee}
            </td>
            <td>
                    ${hkShopUserOrderAfter.phone}
            </td>
            <td>
                    ${hkShopUserOrderAfter.couriernumber}
            </td>
            <td>
                    ${hkShopUserOrderAfter.courier}
            </td>
            <td>
                <fmt:formatDate value="${hkShopUserOrderAfter.updateDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
            </td>
            <td>
                    ${hkShopUserOrderAfter.remarks}
            </td>
                <%--<shiro:hasPermission name="shop:order:hkShopUserOrderAfter:edit"><td>
                    <a href="${ctx}/shop/order/hkShopUserOrderAfter/form?id=${hkShopUserOrderAfter.id}">修改</a>
                    <a href="${ctx}/shop/order/hkShopUserOrderAfter/delete?id=${hkShopUserOrderAfter.id}" onclick="return confirmx('确认要删除该订单售后吗？', this.href)">删除</a>
                </td></shiro:hasPermission>--%>

            <shiro:hasPermission name="shop:order:hkShopUserOrderAfter:edit">
                <td>
                    <a href="${ctx}/shop/order/hkShopUserOrderAfter/form?id=${hkShopUserOrderAfter.id}">查看</a>
                    <c:choose>
                        <c:when test="${hkShopUserOrderAfter.afterstate eq '60'}">
                            <%--<a href="${ctx}/shop/order/hkShopUserOrderAfter/agreeReturnOfGoods?id=${hkShopUserOrderAfter.id}">
                                <font color="#2e8b57">同意退货</font></a>--%>
                            <a href="javascript:"
                               onclick="showLogistics('${hkShopUserOrderAfter.ordernumber}','${hkShopUserOrderAfter.id}')">
                                <font color="#2e8b57">同意退货</font></a>
                            <a href="${ctx}/shop/order/hkShopUserOrderAfter/refuseReturnOfGoods?id=${hkShopUserOrderAfter.id}">
                                <font color="#ff4500">拒绝退货</font></a>
                        </c:when>
                        <c:when test="${hkShopUserOrderAfter.afterstate eq '70'}">
                            <a href="${ctx}/shop/order/hkShopUserOrderAfter/agreeReimburse?id=${hkShopUserOrderAfter.id}">
                                <font color="#9932cc">同意退款</font></a>
                            <a href="${ctx}/shop/order/hkShopUserOrderAfter/refuseReimburse?id=${hkShopUserOrderAfter.id}">
                                <font color="orange">拒绝退款</font></a>
                        </c:when>
                        <c:when test='${hkShopUserOrderAfter.afterstate eq "30"}'>
                            <font color="black">已同意退款</font>
                        </c:when>
                        <c:when test='${hkShopUserOrderAfter.afterstate eq "40"}'>
                            <font color="black">已拒绝退款</font>
                        </c:when>
                        <c:when test='${hkShopUserOrderAfter.afterstate eq "80"}'>
                            <font color="black">已拒绝退货</font>
                        </c:when>
                        <c:otherwise>
                            <font color="black">其它原因</font>
                        </c:otherwise>
                    </c:choose>
                </td>
            </shiro:hasPermission>
        </tr>
    </c:forEach>
    </tbody>
</table>
<div id="logistics"
     style="display: none;margin-left: 0%; width: 100%; background-color: #F2F2F2; height: 200px; position:fixed;
            bottom: 40%; line-height: 0; z-index: 150;">
    <div style="height:40px;">
        <label style="font-size:16px; font-weight: bold; padding-top: 7px; padding-left: 40%;">填写物流信息</label>
    </div>

    <div style="height: 150px;">
        <table class="table table-bordered" border="1" style="text-align: center;height: 150px;">
            <thead>
            <tr>
                <th>收货人</th>
                <th>联系电话</th>
                <th>省</th>
                <th>市</th>
                <th>区/县</th>
                <th>收货地址</th>
                <%--<th>操作</th>--%>
            </tr>
            </thead>
            <tbody>
            <tr class="active">
                <td>
                    <input type="text" id="receiptName" value="" class="required">
                </td>
                <td>
                    <input type="text" id="receiptPhone" value="" class="required">
                </td>
                <td>
                    <sys:treeselect id="province" name="province.id" value="${hkShopUserOrderAfter.area.provinceId}"
                                    labelName="" labelValue="${hkShopUserOrderAfter.area.name}"
                                    title="区域" url="/sys/area/treeData" cssClass="" allowClear="true"
                                    notAllowSelectParent="false"/>
                </td>
                <td>
                    <sys:treeselect id="city" name="city.id" value="${hkShopUserOrderAfter.area.cityId}" labelName=""
                                    labelValue="${hkShopUserOrderAfter.area.name}"
                                    title="区域" url="/sys/area/treeData" cssClass="" allowClear="true"
                                    notAllowSelectParent="false"/>
                </td>
                <td>
                    <sys:treeselect id="area" name="area.id" value="${hkShopUserOrderAfter.area.id}"
                                    labelName="area.name" labelValue="${hkShopUserOrderAfter.area.name}"
                                    title="区域" url="/sys/area/treeData" cssClass="" allowClear="true"
                                    notAllowSelectParent="true"/>
                </td>
                <td>
                    <textarea type="text" id="receipAddress" value="" class="required"></textarea>
                </td>
            </tr>
            <tr>
                <td colspan="3" style="padding-left: 40%">
                    <button id="deliver" class="btn btn-primary">确认</button>
                </td>
                <td colspan="3" style="padding-left: 5%">
                    <button id="closeBtn" class="btn btn-warning">关闭</button>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
<div class="pagination">${page}</div>
<script type="text/javascript">
    var orderNum = "";
    var afterId = "";
    //提交物流信息
    $("#deliver").click(function () {
        var flag = true;
        if ($("#receiptName").val() == null || $("#receiptName").val() == "" || $("#receiptPhone").val() == null || $("#receiptPhone").val() == "" || $("#receipAddress").val() == null || $("#receipAddress").val() == "" ||
            $("#provinceId").val() == null || $("#provinceId").val() == "" || $("#cityId").val() == null || $("#cityId").val() == "" || $("#areaId").val() == null || $("#areaId").val() == "") {
            flag = false;
            alert("请完整填写物流信息");
        }

        if (flag) {
            //提交物流信息
            $.ajax({
                type: "POST",
                url: "${ctx}//shop/order/hkShopUserOrderAfter/logisticsMsg",
                contentType: 'application/x-www-form-urlencoded;charset=utf-8',
                data: {
                    orderNum: orderNum,
                    ids: afterId,
                    receiptName: $("#receiptName").val(),
                    receiptPhone: $("#receiptPhone").val(),
                    province: $("#provinceId").val(),
                    city: $("#cityId").val(),
                    area: $("#areaId").val(),
                    receipAddress: $("#receipAddress").val()
                },
                success: function (res) {
                    window.location.reload();
                    $("#logistics").hide();
                },
                error: function (res) {
                    alert("物流信息提交失败，请稍后重试。");
                }
            });
        }
    });


    //显示物流信息
    function showLogistics(orderNumber, ids) {
        orderNum = orderNumber;
        afterId = ids;
        $("#logistics").show();
        /*$("#express").empty();
        $.ajax({
            type: "GET",
            url: "\\${ctx}/shop/order/hkShopUserOrder/getExpressCompay",
            contentType: 'application/x-www-form-urlencoded;charset=utf-8',
            dataType: 'json',
            success: function (res) {
                $.each(res, function (n, value) {
                    $("#express").append(
                        "<option value='" + value.abbreviation + "'>" + value.name + "</option>"
                    )
                });
                $("#logistics").show();
            },
            error: function (res) {

            }
        });*/

    }

    //隐藏物流信息
    $("#closeBtn").click(function () {
        $("#logistics").hide();
    });
</script>
</body>
</html>